// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   CMIStudentPreference.java

package com.iphaeton.lms.course.scorm12.datamodel.cmi;

import com.iphaeton.lms.course.scorm12.DebugIndicator;
import com.iphaeton.lms.course.scorm12.datamodel.Element;
import java.io.PrintStream;
import java.io.Serializable;

// Referenced classes of package com.iphaeton.lms.course.scorm12.datamodel.cmi:
//            CMICategory, CMIRequest, DMErrorManager

public class CMIStudentPreference extends CMICategory
    implements Serializable
{

    public CMIStudentPreference()
    {
        super(true);
        audio = new Element("", "checkSInteger", "NULL", true, true, true);
        language = new Element("", "checkString255", "NULL", true, true, true);
        speed = new Element("", "checkSInteger", "NULL", true, true, true);
        text = new Element("", "checkSInteger", "NULL", true, true, true);
    }

    public Element getAudio()
    {
        return audio;
    }

    public Element getLanguage()
    {
        return language;
    }

    public Element getSpeed()
    {
        return speed;
    }

    public Element getText()
    {
        return text;
    }

    public void setAudio(String inAudio)
    {
        audio.setValue(inAudio);
    }

    public void setLanguage(String inLanguage)
    {
        language.setValue(inLanguage);
    }

    public void setSpeed(String inSpeed)
    {
        speed.setValue(inSpeed);
    }

    public void setText(String inText)
    {
        text.setValue(inText);
    }

    public String performGet(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        String result = new String("");
        if(isValidStPrefRequest(theRequest))
        {
            String token = theRequest.getNextToken();
            if(theRequest.hasMoreTokensToProcess())
            {
                if(_Debug)
                {
                    System.out.println("Error - Data Model Element not implemented");
                    System.out.println("Invalid data model element: " + theRequest.getRequest() + " passed to interface");
                }
                if(theRequest.isAKeywordRequest())
                    dmErrorMgr.recGetKeyWordError(theRequest.getElement());
                else
                    dmErrorMgr.recNotImplementedError(theRequest);
            } else
            if(theRequest.isAChildrenRequest())
                result = getChildren();
            else
                result = determineElementValue(this, token, dmErrorMgr);
        } else
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Invalid data model element: " + theRequest.getRequest() + " passed to interface");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        theRequest.done();
        return result;
    }

    public void performSet(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        if(isValidStPrefRequest(theRequest))
        {
            String token = theRequest.getNextToken();
            if(theRequest.hasMoreTokensToProcess())
            {
                if(_Debug)
                {
                    System.out.println("Error - Data Model Element not implemented");
                    System.out.println("Invalid data model element: " + theRequest.getRequest() + " passed to interface");
                }
                dmErrorMgr.recNotImplementedError(theRequest);
            } else
            if(theRequest.isAChildrenRequest())
            {
                if(_Debug)
                    System.out.println("Error - trying to set a keyword");
                dmErrorMgr.recKeyWordError(token);
            } else
            {
                String value = theRequest.getValue();
                if(token.equals("audio") || token.equals("speed") || token.equals("text"))
                    try
                    {
                        int ivalue = Integer.parseInt(value);
                        if(token.equals("audio") && ivalue >= -1 && ivalue <= 100 || token.equals("speed") && ivalue >= -100 && ivalue <= 100 || token.equals("text") && ivalue >= -1 && ivalue <= 1)
                            doSet(this, token, value, dmErrorMgr);
                        else
                            dmErrorMgr.SetCurrentErrorCode("405");
                    }
                    catch(NumberFormatException nfe)
                    {
                        dmErrorMgr.SetCurrentErrorCode("405");
                        if(_Debug)
                            System.out.println("Error - Number Format Exception");
                    }
                else
                    doSet(this, token, value, dmErrorMgr);
            }
        } else
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Invalid data model element: " + theRequest.getRequest() + " passed to interface");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        theRequest.done();
    }

    private boolean isValidStPrefRequest(CMIRequest theRequest)
    {
        boolean rtrnFlag = false;
        if(theRequest.getTotalNumTokens() >= CMISTPREF_MIN_NUM_TOKENS)
            rtrnFlag = true;
        return rtrnFlag;
    }

    private String getChildren()
    {
        String children = new String("audio,language,speed,text,");
        return children;
    }

    private static final long serialVersionUID = 0x48814be346eaea03L;
    private static boolean _Debug;
    public Element audio;
    public Element language;
    public Element speed;
    public Element text;
    static int CMISTPREF_MIN_NUM_TOKENS = 3;

    static 
    {
        _Debug = DebugIndicator.ON;
    }
}
